<?php

namespace app\admin\model;

use think\Model;


class User extends Model
{

    

    

    // 表名
    protected $name = 'user';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'sex_text',
        'created_time_text',
        'is_singe_text',
        'last_login_time_text',
        'panda_time_text'
    ];
    

    
    public function getSexList()
    {
        return ['1' => __('Sex 1'), '2' => __('Sex 2')];
    }

    public function getIsSingeList()
    {
        return ['1' => __('Is_singe 1'), '0' => __('Is_singe 0')];
    }


    public function getSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
        $list = $this->getSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCreatedTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['created_time']) ? $data['created_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getIsSingeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_singe']) ? $data['is_singe'] : '');
        $list = $this->getIsSingeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getLastLoginTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['last_login_time']) ? $data['last_login_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getPandaTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['panda_time']) ? $data['panda_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreatedTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setLastLoginTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPandaTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
